package menuedit;

import java.util.List;

import datacontainers.Dish;
import datacontainers.Menu;

public class MenuEditor {

	private Menu menu = new Menu();
	private int addDishId = -1;

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public Menu getMenu() {

		return menu;
	}

	public void updateDish(Dish dish) {
		List<Dish> dishes = menu.getCategory(dish.getCategory());
		int dishIndex = dishes.indexOf(dish);
		if (dishIndex != -1) {
			if (dishes.get(dishIndex).getId() == dish.getId())
				dishes.set(dishIndex, dish);
		}
	}

	public void deleteDish(Dish dish) {
		List<Dish> dishes = menu.getCategory(dish.getCategory());
		if (dishes.indexOf(dish) != -1) {
			dishes.remove(dish);
		}
	}

	public void addDish(Dish dish) {
		if (dish.getId() == 0) {
			dish.setId(addDishId);
			addDishId--;
		}
		List<Dish> dishes = menu.getCategory(dish.getCategory());
		if (dishes.indexOf(dish) == -1) {
			dishes.add(dish);
		}
	}

}
